package com.endbd.systemmanagement.controller.area;

import com.endbd.feignapi.model.system.City;
import com.endbd.feignapi.model.system.Province;
import com.endbd.systemmanagement.model.AreaCondition;
import com.endbd.systemmanagement.model.ResultBody;
import com.endbd.systemmanagement.service.area.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/system")
@RestController
public class AreaController {

  @Autowired
  private AreaService areaService;

  @GetMapping("/area/areaList")
  public ResultBody getAreaList(){
    ResultBody resultBody = new ResultBody();
    List<Province> list=areaService.getAreaList();
    if(list.isEmpty()){
      resultBody.setCode(500);
      resultBody.setMessage("数据获取失败");
    }else{
      resultBody.setCode(200);
      resultBody.setMessage("success");
      resultBody.setData(list);
    }
    return resultBody;
  }

  @PostMapping("/area/query")
  public ResultBody queryArea(@RequestBody AreaCondition areaCondition){
    ResultBody resultBody = new ResultBody();
    Province o=areaService.queryArea(areaCondition);
    if(o==null){
      resultBody.setMessage("暂无相关数据");
      resultBody.setCode(500);
    }else{
      resultBody.setData(o);
      resultBody.setMessage("success");
      resultBody.setCode(200);
    }
    return resultBody;
  }

  //根据城市id或城市名查询城市信息和省份信息
  @PostMapping("/area/queryCity")
  public ResultBody queryCity(@RequestBody AreaCondition areaCondition){
    ResultBody resultBody = new ResultBody();
    City o=areaService.queryCity(areaCondition);
    if(o==null){
      resultBody.setMessage("暂无相关数据");
      resultBody.setCode(500);
    }else{
      resultBody.setData(o);
      resultBody.setMessage("success");
      resultBody.setCode(200);
    }
    return resultBody;
  }

}
